<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true">
				<el-form-item>
					<el-input v-model="keyword" placeholder="关键字"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="warning" v-on:click="keywordQuery">查询</el-button>
				</el-form-item>

			</el-form>
		</el-col>

		<!--列表v-loading="listLoading"-->
		<el-table :data="tableDatas" v-loading="listLoading"  highlight-current-row
			style="width: 100%;">

			<el-table-column type="index" width="70" label="序号">
			</el-table-column>
			<el-table-column prop="name" label="权限名称" width="200">
			</el-table-column>

			<el-table-column prop="url" label="权限地址" width="200">
			</el-table-column>
			<el-table-column prop="decs" label="权限描述" width="200">
			</el-table-column>
			<el-table-column prop="sn" label="权限编码" >
			</el-table-column>
			<el-table-column label="操作">
				<template scope="scope">
					
					<el-button type="danger" size="small" @click="handleDel(scope.row)">删除</el-button>
				</template>
			</el-table-column>

		</el-table>
		<!--工具条-->
		<el-col :span="24" class="toolbar">
			<!-- <el-button type="danger" :disabled="this.sels.length === 0" @click="handlePatchDel">批量删除</el-button> -->
			<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage"
				:page-sizes="[5, 10, 15]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper"
				:total="totals" style="float:right;">
			</el-pagination>
		</el-col>







	</section>
</template>

<script>

export default {
	data() {
		return {
			//1.分页查询相关数据
			totals: 0,//总记录条数
			currentPage: 1,//当前页,要传递到后台的
			pageSize: 5, //每页显示多少条
			tableDatas: [], //当前页数据
			listLoading: false,
			typeTree: [],
			//2.高级查询相关数据
			keyword: '',




		}
	},
	methods: {
		//1.分页查询相关方法
		//1.1.获取列表数据
		getTableData() {
			this.listLoading = true;
			this.$http.post("/permission", {
				"currentPage": this.currentPage,
				"pageSize": this.pageSize,
				"keyword": this.keyword
			}).then(res => {
				this.tableDatas = res.data.list
				this.totals = res.data.total
				this.listLoading = false
			}).catch(res => {
				this.$message("请求错误,请稍后重试")
				this.listLoading = false
			})
		},
		//1.2.选择第几页时触发
		handleCurrentChange(currentPage) {
			this.currentPage = currentPage
			this.getTableData()
		},
		//1.3.选择每页显示记录条数时触发
		handleSizeChange(pageSize) {
			this.pageSize = pageSize
			this.getTableData()
		},
		handleDel(row) {
			this.$confirm('确认是否删除该文件', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			}).then(() => {
				this.$http.delete("/permission/" + row.id).then(res => {
					if (res.data.success) {
						this.$message.success("删除成功")
						this.getTableData()
					} else {

						this.$message.warning("删除失败")
					}
				})
			}).catch(() => {

				this.$message.danger("请求错误,请稍后重试")
			});
		},

		//2.高级查询相关方法
		keywordQuery() {

			// this.$http.get("/user/keywordQuery",{

			// 	"keyword":this.keyword
			// }).then(res=>{
			// 	this.tableDatas=res.data.list
			// }).catch(res=>{

			// 	this.$message("请求错误,请稍后重试")
			// })
			this.currentPage = 1;
			/* 初始化当前页面,高级查询应当从第一页开始搜索 */
			this.getTableData();


		},



	},
	mounted() {
		this.getTableData();
	}
}

</script>

<style scoped></style>
